﻿using JetBrains.ReSharper.Feature.Services.Bulbs;
using JetBrains.ReSharper.Feature.Services.CSharp.Bulbs;
using JetBrains.ReSharper.Psi;
using JetBrains.ReSharper.Psi.CSharp.Tree;
using MugenMvvmToolkit.ReSharper.Infrastructure;

namespace MugenMvvmToolkit.ReSharper.Arguments.ContextActions
{
    [ContextAction(Name = "NotBeNullContextAction", Group = "C#", Priority = 101)]
    public class NotBeNullContextAction : ArgumentContextAction
    {
        #region Constructors

        public NotBeNullContextAction(ICSharpContextActionDataProvider provider)
            : base(provider)
        {
        }

        #endregion

        #region Overrides of ArgumentContextActionBase

        /// <summary>
        ///     Popup menu item text
        /// </summary>
        public override string Text
        {
            get { return UiResources.AddNotBeNull; }
        }

        protected override IMethod Method
        {
            get { return MethodProvider.ShouldNotBeNull; }
        }

        protected override bool IsCheckMethod(IMethod method, IParameter parameter, IArgumentList argumentList)
        {
            return HasCheckMethod(method) && IsParameterUsage(argumentList.Arguments[0].Value, parameter);
        }

        #endregion

        #region Methods

        private bool HasCheckMethod(IMethod method)
        {
            return method.Equals(Method) ||
                   method.Equals(MethodProvider.ShouldNotBeNullOrEmptyEnumerable) ||
                   method.Equals(MethodProvider.ShouldNotBeNullOrEmptyString) ||
                   method.Equals(MethodProvider.ShouldNotBeNullOrWhitespace) ||
                   method.Equals(MethodProvider.ShouldNotBeNullOrDefault);
        }

        #endregion
    }
}